<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <%@include file="../../../../resources/inc/head.jsp" %>
    <!--MiniUI-->
    <link href="<%=basePath%>resources/lib/miniui/themes/default/miniui.css" rel="stylesheet" type="text/css" />
    <script src="<%=basePath%>resources/lib/miniui/miniui.js" type="text/javascript"></script>
    <script src="http://www.miniui.com/demo/pagertree/pagertree.js"></script>
    <style>
        .mini-grid-table,.mini-panel-border{
            border: 1px solid #e6e6e6;
        }
        .mini-grid-headerCell{
            background: none;background-color: #f2f2f2;padding: 5px 0;border-color: #e6e6e6;

        }
        .mini-grid-filterCell, .mini-grid-summaryCell{
            padding: 5px 0;border-top: none;border-left: none;
        }
        .mini-grid-headerCell-outer,.mini-grid-cell-inner, .mini-grid-headerCell-inner{
            height: 28px;line-height: 28px;
        }
        .mini-grid-cell, .mini-grid-headerCell, .mini-grid-filterCell, .mini-grid-summaryCell{

        }
        .mini-toolbar{
            border: none;background:none;width: 100%;min-height: 50px;line-height: 30px;padding: 10px 15px; border: 1px solid #e6e6e6;background-color: #f2f2f2;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div style="width:100%;">
                <div class="mini-toolbar" >
                    <button class="layui-btn layui-btn-sm" lay-event="add" id="add">新增</button>
                </div>
            </div>
            <div id="treegrid1" class="mini-treegrid"  allowResize="true"
                 url="<%=basePath%>manager/productCategory/treeGrid.html?method=LoadNodes" showTreeIcon="true" textField="text" idField="id"
                 treeColumn="filename" onbeforeload="onBeforeTreeLoad" ondrawcell="OnDrawCell">
                <div property="columns">
                    <div type="indexcolumn" align="center" headerAlign="center">序号</div>
                    <div name="filename" width="200" field="productCategoryName" headerAlign="center">分类名称</div>
                    <div field="productCategoryKeywords" width="100"  headerAlign="center">关键字</div>
                    <div field="gmtModified" dateFormat="yyyy-MM-dd HH:mm:ss" width="100" align="center" headerAlign="center">最后修改时间</div>
                    <div name="action" width="120" headerAlign="center" align="center" renderer="onActionRenderer" cellStyle="padding:0;">操作</div>
                </div>
            </div>
        </div>

        <script type="text/javascript">
            $("#treegrid1").css("height",(window.screen.height-350)+"px");
            mini.parse();
            var tree = mini.get("treegrid1");
            var treeid = 0;
            tree.load({
                id: treeid
            });
            function onActionRenderer(e) {
                var grid = e.sender;
                var record = e.record;
                var id = record.id;
                var rowIndex = e.rowIndex;

                var s = ' <a class="layui-btn layui-btn-normal layui-btn-xs " onclick="doEdit(this)" lay-event="edit"   data-id="'+id+'">编辑</a>'
                    + '<a class="layui-btn layui-btn-danger layui-btn-xs delBth" onclick="doDel(this)" lay-event="del"  data-id="'+id+'">删除</a>';
                return s;
            }

            function onBeforeTreeLoad(e) {
                var tree = e.sender;    //树控件
                var node = e.node;      //当前节点
                var params = e.params;  //参数对象
            }

            function OnDrawCell(e) {
                if (e.field == "gmtModified") {
                    if (e.value) {
                        var date = new Date();
                        date.setTime(e.value);
                        e.cellHtml =date.Format("yyyy-MM-dd hh:mm:ss");
                    }else{
                        e.cellHtml = "";
                    }
                }else if (e.field == "showInNav") {
                    if (e.value || e.value==1) {
                        e.cellHtml ="<span class=\"layui-badge layui-bg-green\">显示</span>";
                    }else{
                        e.cellHtml = "<span class=\"layui-badge layui-bg-gray\">不显示</span>\n";
                    }
                }else if (e.field == "isShow") {
                    if (e.value || e.value==1) {
                        e.cellHtml ="<span class=\"layui-badge layui-bg-green\">显示</span>";
                    }else{
                        e.cellHtml = "<span class=\"layui-badge layui-bg-gray\">不显示</span>\n";
                    }
                }else if (e.field == "productTypeId") {
                    if (e.value ) {
                        console.log(e)
                        // e.cellHtml =e.row.productType.productTypeName;
                    }
                }

            }


        </script>
    </div>
</div>

<%@include file="../../../../resources/inc/footer.jsp" %>
<script>
    var  layer=null;
    layui.config({
        base: '<%=basePath%>resources/lib/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
    }).use(['index', 'table'], function () {
        var $ = layui.$
            , form = layui.form;
        $("#add").click(function () {
            var dialog=new UtilClass.LayerDialog({
                title: '添加产品分类'
                ,content: '<%=basePath%>manager/productCategory/create.html'
            });
            dialog.layerShow();
        })
        $("#dels").click(function () {
        })
    });
    function doEdit(obj) {
        var id=$(obj).attr("data-id");
        var dialog=new UtilClass.LayerDialog({
            title: '编辑产品分类'
            ,content: '<%=basePath%>manager/productCategory/update/'+id+'.html'
        });
        dialog.layerShow();
    }
    function doDel(obj) {
        var id=$(obj).attr("data-id");
        layer.confirm("真的删除行么", function (t) {
            layer.close(t);
            $.ajax({
                url:"<%=basePath%>manager/productCategory/delete/"+id+".html",
                type:"get",
                dataType:"JSON",
                success:function (data) {

                    if(data.success){
                        layer.msg("删除成功", {time: 1000});
                        setTimeout(function () {
                            window.location.reload()
                        },1000);

                    }else{
                        layer.msg(data.message)
                    }
                }
            });

        })

    }

</script>
</body>
</html>

